package cn.bellychang.leetcode.question145;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ChangLiang
 * @date 2021/2/7
 */
public class Solution {

    private List<Integer> list = new ArrayList<>();

    public List<Integer> postorderTraversal(TreeNode root) {
        traverse(root);
        return list;
    }

    public void traverse(TreeNode treeNode) {
        if (treeNode == null) {
            return;
        }
        if (treeNode.right == null && treeNode.left == null) {
            list.add(treeNode.val);
            return;
        }
        traverse(treeNode.left);
        traverse(treeNode.right);
        list.add(treeNode.val);
    }
}
